<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS 引入elementUI 的CSS-->
    <link rel="stylesheet" href="./css/index.css">
    <!--    引入axios 的CSS-->
    <script src="./js/axios.min.js"></script>
    <!-- import Vue before Element 引入 VUE.js-->
    <script src="./js/vue.min.js"></script>
    <!-- import JavaScript  引入 element UI.js-->
    <script src="./js/index.min.js"></script>

    <style>
        header a {
            text-decoration: none;
            color: #6c6c6c;
        }

        .el-table .el-table__cell {
            padding: 0; /*去掉表格中每一行自带的内边距*/
        }

        .el-table .cell {
            white-space: nowrap; /*让内容在一行中显示*/
            /* text-overflow: ellipsis;*//*文本内容超出范围时用省略号表示*/
        }

        .p_img:hover {
            position: relative;
            top: 5px;
            /*设置元素阴影:x偏移值 y偏移值 浓度 范围 颜色*/
            box-shadow: 0 0 10px 5px #333;
        }
        .el-main a{
            color: black;
            text-decoration: none;
        }
        .el-main a:hover{
            color: #666;
        }
    </style>
</head>
<body>

<style>
    .layout-aside i {
        color: #fff !important;
    }
</style>
<div id="app">
    <el-breadcrumb separator="/">
        <el-breadcrumb-item><a href="/index.html">任务管理</a></el-breadcrumb-item>
        <el-breadcrumb-item><a href="/addNew.html">新建任务</a></el-breadcrumb-item>
        <el-breadcrumb-item><a href="/databaseConfig.html">数据库配置</a></el-breadcrumb-item>
        <el-breadcrumb-item><a href="/FTPConfig.html">FTP配置</a></el-breadcrumb-item>
        <el-breadcrumb-item><a href="/addNew.html">数据库引用</a></el-breadcrumb-item>
        <el-breadcrumb-item>日志跟踪</el-breadcrumb-item>
        <el-breadcrumb-item>消息提醒</el-breadcrumb-item>
    </el-breadcrumb>
    
    <el-divider></el-divider>
    
    <el-card>
        <template>
            <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
                <el-tab-pane label="数据推送" name="first">
                    <template>
                        <el-table :data="tableData" style="width: 100%" :row-class-name="tableRowClassName">
                            <el-table-column prop="tid" label="任务ID"  align="center"></el-table-column>
                            <el-table-column prop="taskName" label="任务名称" align="center"></el-table-column>
                            <el-table-column prop="jobGroup" label="工作组" align="center"></el-table-column>
                            <el-table-column prop="cron"     label="Cron" align="center"></el-table-column>
                            <el-table-column prop="delStatus" label="状态" align="center">
                                <template slot-scope="scope">
                                    <el-tag v-if="scope.row.delStatus=== '1'" type="success">运行中</el-tag>
                                    <el-tag v-if="scope.row.delStatus=== '0'" type="info" >已暂停</el-tag>
                                    <el-tag v-if="scope.row.delStatus=== '-1'">未注册</el-tag>
                                </template>
                            </el-table-column>
                            <el-table-column prop="createTime" label="创建时间" align="center"></el-table-column>
                            <el-table-column  width="300" label="操作" align="center">
                                <template slot-scope="scope">
                                    <el-button size="small" round type="success" @click="start(scope.row.tid)">启动</el-button>
                                    <el-button size="small" round type="warning" @click="pause(scope.row.tid)">暂停</el-button>
                                    <el-button size="small" round type="info"    @click="resume(scope.row.tid)">恢复</el-button>
                                    <el-button size="small" round type="danger"  @click="remove(scope.row.tid)">删除</el-button>
                                </template>
                            </el-table-column>

                        </el-table>
                    </template>
                </el-tab-pane>
                <el-tab-pane label="文件删除" name="second">

                </el-tab-pane>
                <el-tab-pane label="接口收发" name="third">

                </el-tab-pane>
                <el-tab-pane label="SQL定时执行" name="fourth">

                </el-tab-pane>
            </el-tabs>
        </template>
    </el-card>
</div>

</body>

<style>
    .el-table .warning-row {
        background: oldlace;
    }

    .el-table .success-row {
        background: #f0f9eb;
    }
    .deleted-row {
        background-color: #ffe6e6; /* 设置删除状态的行背景色 */
    }
</style>

<script>
    let v = new Vue({
        el: '#app',
        data: function () {
            return {
                tableData: [],
                activeName: 'first'
            }
        },
        methods: {
            tableRowClassName({ row }) {
                // 根据状态值为2时标记整列数据为红色
                return row.delStatus === '2' ? 'red-row' : '';
            },
            handleClick(tab, event) {
                console.log(tab, event);
            },
            start(id){
                let data = new FormData();
                data.append('id', id)
                axios.post('/api/start', data)
                    .then(function (response) {
                        if (response.data.code === 200000) {
                            v.$message.success(response.data.msg);
                            v.list();
                        } else {
                            v.$message.error(response.data.msg);
                        }
                    })
            },
            pause(id){
                let data = new FormData();
                data.append('id', id)
                axios.post('/api/pause', data)
                    .then(function (response) {
                        if (response.data.code === 200000) {
                            v.$message.success(response.data.msg);
                            v.list();
                        } else {
                            v.$message.error(response.data.msg);
                        }
                    })
            },
            resume(id){
                let data = new FormData();
                data.append('id', id)
                axios.post('/api/resume', data)
                    .then(function (response) {
                        if (response.data.code === 200000) {
                            v.$message.success(response.data.msg);
                            v.list();
                        } else {
                            v.$message.error(response.data.msg);
                        }
                    })
            },
            remove(id){
                let data = new FormData();
                data.append('id', id)
                axios.post('/api/remove', data)
                    .then(function (response) {
                        if (response.data.code === 200000) {
                            v.$message.success(response.data.msg);
                            v.list();
                        } else {
                            v.$message.error(response.data.msg);
                        }
                    })
            },
            list(){
                const apiUrl = '/export/list'; // 接口地址
                const vm = this; // 保存 Vue 实例的引用
                axios.get(apiUrl)
                    .then(function (response) {
                        if (response.data.code == 200000) {
                            vm.tableData = response.data.result;
                            console.log(vm.tableData);
                        } else {
                            vm.$message.error(response.data.msg);
                        }
                    });
            }

        },
        //页面周期函数
        created: function () {
            this.list();
        }
    })
</script>
</html>
